Expand description
Harness
for discovering test inputs and asserting against snapshot files
This is a custom test harness and should be put in its own test binary with
test.harness = false
.
§Examples
fn some_func(num: usize) -> usize {
// ...
}
tryfn::Harness::new(
"tests/fixtures/invalid",
setup,
test,
)
.select(["tests/cases/*.in"])
.test();
fn setup(input_path: std::path::PathBuf) -> tryfn::Case {
let name = input_path.file_name().unwrap().to_str().unwrap().to_owned();
let expected = tryfn::Data::read_from(&input_path.with_extension("out"), None);
tryfn::Case {
name,
fixture: input_path,
expected,
}
}
fn test(input_path: &std::path::Path) -> Result<usize, Box<dyn std::error::Error>> {
let raw = std::fs::read_to_string(input_path)?;
let num = raw.parse::<usize>()?;
let actual = some_func(num);
Ok(actual)
}
Structs§
- Test fixture, actual output, or expected result
Harness
for discovering test inputs and asserting against snapshot files
Enums§
- Describes the structure of
Data